package com.mfl.mapper;

import com.github.pagehelper.Page;
import com.mfl.pojo.dto.UserPageQueryDTO;
import com.mfl.pojo.entity.User;
import com.mfl.pojo.vo.UserPageQueryVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {

    /**
     * 根据用户名查询用户信息
     * @param userName
     * @return
     */
    @Select("select * from user where user_name = #{userName}")
    User getByUserName(String userName);

    /**
     * 添加用户信息
     * @param user
     */
    void insert(User user);

    /**
     * 分页查询用户信息
     * @param userPageQueryDTO
     * @return
     */
    Page<UserPageQueryVO> pageQuery(UserPageQueryDTO userPageQueryDTO);

    /**
     * 更新用户状态
     * @param status
     * @param id
     */
    @Update("update user set status = #{status} where id = #{id}")
    void updateStatus(Integer status, Integer id);

    /**
     * 批量删除用户信息
     * @param ids
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 根据id查询用户信息
     * @param id
     * @return
     */
    @Select("select * from user where id = #{id}")
    User getById(int id);

    /**
     * 更新用户信息
     * @param user
     */
    void update(User user);

    /**
     * 校验密码是否正确
     * @param user
     * @return
     */
    @Select("select * from user where id = #{id} and user_pwd = #{userPwd}")
    Boolean checkPwd(User user);

    /**
     * 更新用户密码
     * @param user
     */
    @Update("update user set user_pwd = #{userPwd} where id = #{id}")
    void updatePwd(User user);
}
